package main.java.chessfootball.rules.checker;

import main.java.chessfootball.model.regulation.Mode;

/**
 * User: Igor
 * Date: 28.07.2011
 * Time: 6:23:00
 */
public class TurnChecker extends AbstractSideChecker
{

	@Override
	public boolean valid()
	{
		if (game.getMatch().getMode().equals(Mode.OUT_GAME))
		{
			if (game.getRule().getMatch().getTimeRule(game.getMatch().getTime().getPeriod()).isIterationOutGame())
			{
				int startPlayer = game.getMatch().getTime().getStartSide().equals(side) ? 1 : 0;
				if (game.getField().getTeam(side).getPlayersCount() != game.getField().getTeam(side.getInvert()).getPlayersCount() + startPlayer)
				{
					return false;
				}
			}
			else
			{
				if (game.getField().getTeam(side).getPlayersCount() != game.getRule().getMatch().getPlayersCount())
				{
					return false;
				}
			}
		}
		return true;
	}
}
